<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('产品上传统计')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<form id="role-form">
			<div class="select-list" style="display: none">
				<ul>
					<li class="select-time">
						<label>时间： </label>
						<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
						<span>-</span>
						<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
					</li>
					<li>
						<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
					</li>
				</ul>
			</div>
		</form>
		<div class="row">
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "statistics";
		$('#startTime').val(getPreviousDay())
		$('#endTime').val(getNextDay())
		$(function() {
			var url = prefix + "/detail?id="+[[${query.id}]];
			var beginTime = [[${query.params.beginTime}]]
			var endTime = [[${query.params.endTime}]]
			if(beginTime != ''){
				url += "&beginTime="+[[${query.params.beginTime}]]
				$("#startTime").val(beginTime)
			}
			if(endTime != ''){
				$("#endTime").val(endTime)
				url += "&endTime="+[[${query.params.endTime}]]
			}
            var options = {
                url: url,
                modalName: "详情",
                columns: [
				{
					field: 'id',
					title: '',
					visible: false
				},
					{
						field: 'pname',
						title: '产品',
						sortable: true
					},

				{
					field: 'fileName',
					title: '文件名称',
					sortable: true
				},
					{
						field: 'type',
						title: '文件格式',
						sortable: true
					},
					/*{
						field: 'bz',
						title: '备注',
						sortable: true
					},*/
				{
					field: 'createDate',
					title: '创建时间',
					sortable: true
				},
				{
					field: 'status',
					title: '状态',
					sortable: true,
					formatter: function(value, item, index) {
						//console.log(item.down_end_date)
						if (item.status == 0){
							return '<span class="label label-warning">异常</span>';
						}
						if (item.status == 1) {
							return '<span class="label label-primary">正常</span>';
						}
						if (item.status == 2) {
							return '<span class="label label-warning">晚传</span>';
						}
						if (item.status == 3) {
							return '<span class="label label-primary">补传</span>';
						}
						return '<span class="label label-primary">未知</span>'

					}
				}]
            };
            $.table.init(options);
		});
		//前一天时间
		function getPreviousDay() {
			const today = new Date(); // 获取当前时间
			const previousDay = new Date(today); // 复制当前时间对象
			previousDay.setDate(today.getDate()); // 将日期减少一天
			return formatDate(previousDay);
		}
		//后一天时间
		function getNextDay() {
			const today = new Date(); // 获取当前时间
			const nextDay = new Date(today); // 复制当前时间对象
			nextDay.setDate(today.getDate() + 1); // 将日期增加一天
			return formatDate(nextDay);
		}
		//时间格式转换
		function formatDate(date) {
			const year = date.getFullYear();
			const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1，并且补零
			const day = String(date.getDate()).padStart(2, '0'); // 日期可能是一位数，需要补零
			return `${year}-${month}-${day}`;
		}
	</script>
</body>
</html>
